package com.aidex.web.controller.biz;

import com.aidex.biz.domain.WxPayUser;
import com.aidex.biz.service.WxPayUserService;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.common.utils.poi.ExcelUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 微信转账到用户零钱Controller
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2022-10-28
 */
@RestController
@RequestMapping("/biz/bizWxPayUser")
public class WxPayUserController extends BaseController {
    @Autowired
    private WxPayUserService wxPayUserService;

    /**
     * 查询微信转账到用户零钱列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizWxPayUser:list')")
    @GetMapping("/list")
    public R<PageInfo> list(WxPayUser wxPayUser, HttpServletRequest request, HttpServletResponse response) {
        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            wxPayUser.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        wxPayUser.setPage(new PageDomain(request, response));
        return R.data(wxPayUserService.findPage(wxPayUser));
    }

    /**
     * 获取微信转账到用户零钱详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizWxPayUser:query')")
    @GetMapping(value = "/{id}")
    public R<WxPayUser> detail(@PathVariable("id") String id) {
        return R.data(wxPayUserService.get(id));
    }

    /**
     * 新增微信转账到用户零钱
     */
    @PreAuthorize("@ss.hasPermi('biz:bizWxPayUser:add')")
    @Log(title = "微信转账到用户零钱", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated WxPayUser wxPayUser) {
        return R.status(wxPayUserService.save(wxPayUser));
    }

    /**
     * 修改微信转账到用户零钱
     */
    @PreAuthorize("@ss.hasPermi('biz:bizWxPayUser:edit')")
    @Log(title = "微信转账到用户零钱", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated WxPayUser wxPayUser) {
        return R.status(wxPayUserService.save(wxPayUser));
    }


    /**
     * 删除微信转账到用户零钱
     */
    @PreAuthorize("@ss.hasPermi('biz:bizWxPayUser:remove')")
    @Log(title = "微信转账到用户零钱", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(wxPayUserService.deleteWxPayUserByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizWxPayUser:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort() {
        return R.data(wxPayUserService.findMaxSort(new WxPayUser()));
    }

    /**
     * 导出微信转账到用户零钱列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizWxPayUser:export')")
    @Log(title = "微信转账到用户零钱", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(WxPayUser wxPayUser) {

        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            wxPayUser.setCompanyId(null);
        } else {
            wxPayUser.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        List<WxPayUser> list = wxPayUserService.findList(wxPayUser);
        ExcelUtil<WxPayUser> util = new ExcelUtil<WxPayUser>(WxPayUser.class);
        return util.exportExcel(list, "微信转账到用户零钱数据");
    }

}
